function [r_times, ri_val, i_val] = stintresc(jmptimes, fval, ...
                                      tm_scale, sp_scale, b_verb)

% STINTRESC Integrate and rescale a piecewice constant function:
%
%      g(t) = 1/b * int^{at} f(s) ds. 
%
% The function is given by two vectors containing the jumps points
% and function values at these points respectively. The result is a
% piecewise linear function. If several scales are given, then
% the resulting processes are stored as column vectors in two
% matrices and truncated at a largest common time. 
%
% The result is the same as that of STRESCINT, but this function is
% slower. The reason is that the integrated piecewise constant
% function is piecewise linear and the truncation operation for the
% latter is more complex.
%
%  [r_times, ri_val, i_val] = stintresc(jmptimes, fval, 
%                                      tm_scale, sp_scale, b_verb)
%
% Inputs: 
%        jmptimes - a vector of the jump points 
%        fval - a vector of function values at the jump points
%        tm_scale - a column vector of "time" scales, parameter [a]
%          above 
%        sp_scale - a column vector of "space" scales, parameter [b]
%          above 
%        b_verb - if 1 then print processing info
%
% Outputs:
%        r_times - a column vector(s) of the break times of the
%          integrated and rescaled function(s) 
%        ri_val - a column vector(s) of values at the break times
%          of the integrated and rescaled function(s) 
%        i_val - a column vector of values at the break times
%          of the integrated function before rescaling
%
% See also STRESCINT, SCALEMGINFTY, SCALEONOFF.

% Authors: R.Gaigalas, I.Kaj
% v1.0 03-Oct-05

  % integrate the piecewice constant function
  i_val = stairintegr(jmptimes, fval);
  
  % rescale time
  % X(at) jumps at t_n/a
  r_times = jmptimes*(1./tm_scale)';
  % rescale space
  ri_val = i_val*(1./sp_scale)';
  
  % cut the piecewise linear processes at the largest common time
  cut_time = min(r_times(end, 1:end));
  [r_times ri_val] = linjpcut(r_times, ri_val, cut_time);

  if b_verb % print info
    fprintf(1, '##Largest common time window: %f\n', cut_time);
  end  
